// const formatNumber = (n) => {
//   n = n.toString();
//   return n[1] ? n : '0' + n;
// };
// export function formatTime(date) {
//   const year = date.getFullYear();
//   const month = date.getMonth() + 1;
//   const day = date.getDate();
//   const hour = date.getHours();
//   const minute = date.getMinutes();
//   const second = date.getSeconds();
//   return [year, month, day].map(formatNumber).join('/') + ' ' + [hour, minute, second].map(formatNumber).join(':');
// };

export function openNav(latitude, longitude, name, address) {
  uni.getLocation({
    type: 'gcj02',
    // 默认为 wgs84 返回 gps 坐标，gcj02 返回可用于 wx.openLocation 的坐标
    success: function (res) {
      // success
      console.log('latitude', res.latitude);
      console.log('longitudees', res.longitude);
      uni.openLocation({
        latitude,
        // 纬度，范围为-90~90，负数表示南纬
        longitude,
        // 经度，范围为-180~180，负数表示西经
        scale: 28,
        // 缩放比例
        name: name,
        address: address
      });
    }
  });
};
export function stationType(type) {
  if (type == 1) {
    return "自运营";
  } else if (type == 2) {
    return "个人桩";
  } else if (type == 3) {
    return "代运营";
  } else if (type == 4) {
    return "销售";
  }
}
export function changeDistance(distance) {
  var dis = (distance / 1000).toFixed(2) + ""
  return dis;
}
// module.exports = {
//   formatTime: formatTime,
//   openNav: openNav,
//   stationType,stationType,
//   changeDistance,changeDistance
// };


export function formatNumber(n) {
  n = n.toString()
  return n[1] ? n : '0' + n
}


//格式化时间 long 转成 2023-11-20 12：12：12
export function formatDate(datetime) {
  var date = new Date(datetime.time)
  var year = date.getFullYear();
  var month = date.getMonth() + 1;
  var day = date.getDate();
  var hh = date.getHours();
  var mm = date.getMinutes();
  var ss = date.getSeconds();
  return [year, month, day].map(formatNumber).join('-') + " " + [hh, mm, ss].map(formatNumber).join(':');
}

//格式化时间 long 转成 2023-11-20 12：12：12
export function formatTime(datetime) {
  var date = new Date(datetime)
  var year = date.getFullYear();
  var month = date.getMonth() + 1;
  var day = date.getDate();
  var hh = date.getHours();
  var mm = date.getMinutes();
  var ss = date.getSeconds();
  return [year, month, day].map(formatNumber).join('-') + " " + [hh, mm, ss].map(formatNumber).join(':');
}



export function getNowTime() {
  // var date = getDate();
  var date = new Date()
  var hh = date.getHours();
  // var mm = date.getMinutes();
  // var ss = date.getSeconds();
  return hh;
}
//转换订单状态  0 1 2   待支付 已支付 充电中
export function orderType(type) {
  if (type == "0") {
    return "待付款";
  }
  if (type == "1") {
    return "已付款";
  }
  if (type == "2") {
    return "充电中";
  }
  if (type == "5") {
    return "充电完成";
  }
  if (type == "6") {
    return "退款完成";
  }
}
export function dpcStatus(stat) {
  if (stat == "0") {
    return "空闲";
  }
  if (stat == "1") {
    return "空闲";
  }
  if (stat == "2") {
    return "充电中";
  }
  if (stat == "-1") {
    return "离线";
  }
  return "";
}

export function orderChargeTime(time) {
  console.log('time: ', time);
  if (time >= 0) {
    var hours = Math.floor(time / 3600);
    var minutes = Math.floor((time % 3600) / 60);
    var remainingSeconds = time % 60;
    return hours + "小时" + minutes + "分钟" + remainingSeconds + "秒";
  } else {
    return '0'
  }
}

export function Price4Point(price) {
  if (price >= 0) {
    return (price / 10000).toFixed(2);
  } else {
    return 0
  }
}
export function addPrice4Point(price1, price2) {
  var price = parseInt(price1) + parseInt(price2);
  if (price >= 0) {
    return (price / 10000).toFixed(2);
  } else {
    return 0
  }
}

export function getDPC(device_code) {
  return device_code.split("_")[0];
}

export function getQiangNum(device_code) {
  return device_code.split("_")[1] == '00' ? '01' : device_code.split("_")[1];
}

export function addPrice(a, b) {
  return ((parseInt(a) + parseInt(b)) / 10000).toFixed(2);
}
